package com.tao.content.api;

import com.tao.base.model.Result;
import com.tao.content.domain.dto.CourseTeacherDto;
import com.tao.content.domain.pojo.CourseTeacher;
import com.tao.content.service.impl.CourseTeacherServiceImpl;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程教师管理
 * </p>
 *
 * @author taohongrun
 * @since 2024/11/7
 */
@RestController
@RequestMapping("/course-teacher")
@RequiredArgsConstructor
@Tag(name = "课程教师管理接口",description = "管理课程教师")
@Slf4j
public class CourseTeacherController {
    final CourseTeacherServiceImpl courseTeacherService;

    @PostMapping("")
    @Operation(summary = "添加课程教师")
    public Result<CourseTeacher> saveCourseTeacher(@Valid @RequestBody CourseTeacherDto courseTeacherDto){
        return Result.success(courseTeacherService.saveCourseTeacher(courseTeacherDto));
    }

    @GetMapping("/{courseId}")
    @Operation(summary = "查询该课程对应教师")
    @Parameter(name = "courseId",description = "查询教师的课程id",in = ParameterIn.PATH)
    public Result<List<CourseTeacher>> getCourseTeacher(@PathVariable("courseId") Long courseId){
        return Result.success(courseTeacherService.getCourseTeacher(courseId));
    }

    @PutMapping("")
    @Operation(summary = "修改课程教师")
    public Result<CourseTeacher> updateCourseTeacher(@RequestBody CourseTeacher courseTeacher){
       return Result.success(courseTeacherService.updateCourseTeacher(courseTeacher));
    }

    @DeleteMapping("/{courseId}/{teacherId}")
    @Operation(summary = "删除课程教师")
    @Parameters(value = {
            @Parameter(name = "courseId",description = "课程id",in = ParameterIn.PATH),
            @Parameter(name = "teacherId",description = "课程id",in = ParameterIn.PATH)
    })
    public Result removeCourseTeacher(@PathVariable("courseId") Long courseId,@PathVariable("teacherId") Long teacherId){
        courseTeacherService.removeCourseTeacher(courseId,teacherId);
        return Result.success();
    }

}
